Skip to content

Conversation

@rgarcia
Copy link
Contributor

@rgarcia rgarcia commented Jan 31, 2026

Summary

The CDP proxy on port 9222 previously only implemented /json/version, which returned the WebSocket URL but didn't support target discovery.

Playwright's connectOverCDP() fetches /json to discover browser targets before establishing a WebSocket connection. Without this endpoint, using http://127.0.0.1:9222 with agent-browser or Playwright would fail, even though direct WebSocket connections (ws://127.0.0.1:9222) worked fine.

Changes

  • Adds /json and /json/list endpoints that proxy to Chrome's /json
  • Rewrites webSocketDebuggerUrl and devtoolsFrontendUrl in the response to use the proxy's host instead of Chrome's internal host
  • Enables agent-browser --cdp http://127.0.0.1:9222 to work correctly

Before

# This worked (direct WebSocket):
agent-browser --cdp ws://127.0.0.1:9222 snapshot  #

# This failed (HTTP with target discovery):
agent-browser --cdp http://127.0.0.1:9222 snapshot  #

After

# Both work now:
agent-browser --cdp ws://127.0.0.1:9222 snapshot   #
agent-browser --cdp http://127.0.0.1:9222 snapshot #

Test plan

  • Run existing devtoolsproxy tests: go test ./lib/devtoolsproxy/...
  • Deploy to a test VM and verify curl http://127.0.0.1:9222/json returns targets with rewritten URLs
  • Test agent-browser --cdp http://127.0.0.1:9222 snapshot works inside a Kernel browser VM

Note

Medium Risk
Introduces new HTTP handlers that fetch and transform upstream browser JSON; failures could break CDP client connectivity or add latency, but changes are isolated to the devtools proxy surface.

Overview
Adds HTTP target-discovery support to the DevTools proxy on :9222 by implementing /json and /json/list (plus trailing-slash variants) that proxy Chrome’s /json response and rewrite webSocketDebuggerUrl/devtoolsFrontendUrl hosts back to the proxy via rewriteWSURL.

Extends /json/version handling to also accept a trailing slash to avoid Playwright 426s, adds new e2e coverage validating the rewritten endpoints and a real agent-browser flow through the proxy, and hardens the devtoolsproxy Chromium restart test by using stdbuf to reduce CI flakiness when waiting for the “DevTools listening” log line.

Written by Cursor Bugbot for commit d2ec4e3. This will update automatically on new commits. Configure here.

…port

The CDP proxy on port 9222 previously only implemented /json/version,
which returned the WebSocket URL but didn't support target discovery.

Playwright's connectOverCDP() fetches /json to discover browser targets
before establishing a WebSocket connection. Without this endpoint, using
`http://127.0.0.1:9222` with agent-browser or Playwright would fail, even
though direct WebSocket connections (ws://127.0.0.1:9222) worked fine.

This change:
- Adds /json and /json/list endpoints that proxy to Chrome's /json
- Rewrites webSocketDebuggerUrl and devtoolsFrontendUrl in the response
  to use the proxy's host instead of Chrome's internal host
- Enables `agent-browser --cdp http://127.0.0.1:9222` to work correctly
Add comprehensive e2e tests verifying that agent-browser can connect
to Chrome through the CDP proxy on port 9222. Tests validate:

- /json endpoint returns targets with URLs rewritten to proxy port
- /json/list endpoint works correctly with URL rewriting
- /json/version endpoint continues to work
- agent-browser works with various --cdp argument formats:
  - port only (9222)
  - http URL (http://127.0.0.1:9222)
  - localhost:port
  - 127.0.0.1:port
- agent-browser snapshot and navigation commands work via proxy
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Rewrite the test to focus on validating the /json and /json/list
endpoints added by the PR:

- Test that /json returns targets with webSocketDebuggerUrl rewritten
  from port 9223 (Chrome) to port 9222 (proxy)
- Test that /json/list works the same way
- Test that /json/version continues to work
- Add comparison test showing Chrome's direct /json on 9223 has
  unrewritten URLs

Remove agent-browser tests since they required additional setup
and the core functionality is validated by the JSON endpoint tests.
The TestUpstreamManagerDetectsChromiumAndRestart test was flaky in CI
because Chromium's stderr output was fully buffered when connected to
a file. The "DevTools listening on ws://..." line would sit in a buffer
and never be flushed until the buffer filled or the process exited,
causing the test to timeout after 20 seconds.

Fix by using stdbuf -oL -eL to force line buffering on both stdout and
stderr, ensuring each line is flushed immediately after the newline.

This also improves test speed from ~17-20s to ~0.5s since we no longer
wait for buffered output.
1. Add HTTP status code check before decoding JSON response from Chrome's
   /json endpoint. Previously, 4xx/5xx responses would result in confusing
   JSON decode errors like "invalid character '<'".

2. Fix devtoolsFrontendUrl rewriting for URLs with ws= query parameter.
   Chrome's devtoolsFrontendUrl often has the format:
   https://chrome-devtools-frontend.appspot.com/.../inspector.html?ws=127.0.0.1:9223/...

   The previous code only replaced the URL's host field, but in this format
   the Chrome host appears in the ws= query parameter. Now we handle both
   cases: direct host replacement and ws= query param replacement.
…2e test

Playwright's connectOverCDP requests /json/version/ with a trailing slash,
which was falling through to the WebSocket handler and returning a 426
"Upgrade Required" error. This prevented agent-browser (and other
Playwright-based tools) from connecting via the CDP proxy on port 9222.

- Register trailing-slash variants for /json, /json/, /json/list, /json/list/,
  /json/version, and /json/version/ endpoints
- Add comprehensive e2e test for agent-browser that:
  - Installs agent-browser globally in the container
  - Tests CDP connection with port number format (--cdp 9222)
  - Tests CDP connection with http:// URL format (--cdp http://127.0.0.1:9222)
  - Verifies navigation, snapshot, get url, and get title commands

This enables natural usage of agent-browser within containers:
  agent-browser --cdp 9222 open https://example.com
  agent-browser --cdp 9222 snapshot --json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants